﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Manage/Views/Shared/Master.Master"
    Inherits="System.Web.Mvc.ViewPage<EAdvertise>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <form method="post" action="">
    <table class="gv">
        <tr>
            <th class="width80 textRight">
                标题
            </th>
            <td>
                <%= Html.TextBox("adTitle",Model.Title) %>
            </td>
            <th class="width80 textRight">
                广告类型
            </th>
            <td>
                <%= Html.DropDownList("adType") %>
                <%= Html.Hidden("adAid",Model.Aid) %>
            </td>
            <th class="width80 textRight">
                扩展标记
            </th>
            <td>
                <%= Html.TextBox("adKey",Model.ExtendKey) %>
                <%= Html.Hidden("adModuleKey",Model.ModuleKey) %>
            </td>
        </tr>
        <tr>
            <th class="textRight">
                友好名称
            </th>
            <td>
                <%= Html.TextBox("adDescription",Model.Description) %>
            </td>
            <th class="textRight">
                排序
            </th>
            <td>
                <%= Html.TextBox("adSequence", Model.Sequence)%>
            </td>
            <th>
            </th>
            <td>
            </td>
        </tr>
    </table>
    <div id="slide_box">
        <table class="gv">
            <tbody>
                <%
                    if ((xTeam.HengLe.Enums.AdType)Model.Type == xTeam.HengLe.Enums.AdType.Slide)
                    {
                        foreach (ESlide item in Model.SlideList)
                        {
                %>
                <tr>
                    <td class="textCenter width120">
                        <img style="cursor: pointer;" title="点击更换图片" src='<%= Url.Action("Thumb","Home",new {s = item.ImageName,Area = "Website"}) %>'
                            alt="" />
                        <%= Html.Hidden("filePath",item.ImageName)%>
                    </td>
                    <td>
                        <span>标题:</span>
                        <%= Html.TextBox("title", item.Title, new { @class = "width300" })%>
                        <br />
                        <span>链接:</span>
                        <%= Html.TextBox("redirect", item.Redirect, new { @class = "width300" })%>
                        <br />
                        <span>排序:</span>
                        <%= Html.TextBox("sequence",item.Sequence,new {@class = "width80"}) %>
                    </td>
                    <td class="textCenter width80">
                        <input type="button" value="删除" name="slide_delete" />
                    </td>
                </tr>
                <%
                    }
                    }
                %>
            </tbody>
        </table>
        <div>
            <input type="button" id="slide_insert" value="插入图片" />&nbsp;
            <input type="submit" value="保存" />
        </div>
    </div>
    <div id="richtext_box">
        <div>
            <%= Html.TextArea(
                "ckeditor"
                ,((xTeam.HengLe.Enums.AdType)Model.Type) == xTeam.HengLe.Enums.AdType.RichText?Model.Contents:string.Empty
                ,  new {rows=20,cols=100,style="width:100%;height:100%;" })
            %>
        </div>
        <div>
            <input type="submit" value="保存" />
        </div>
    </div>
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cssLink" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="jsLink" runat="server">
    <script src="/WebResources/ckeditor/ckeditor_basic.js" type="text/javascript"></script>
    <script src="/WebResources/ckfinder/ckfinder.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="cssContent" runat="server">
    <style type="text/css">
        #slide_box, #richtext_box
        {
            margin: 5px;
            display: none;
        }
    </style>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="jsContent" runat="server">
    <script type="text/javascript">

        var ckfinder = new CKFinder(null, null, 500, "SetUrl");
        function showDialog() {
            var dialog = $("<div title='文件浏览器'></div>")
            dialog.append(ckfinder.CreateHtml());
            dialog.dialog(
            {
                modal: true
                , width: 800
                , close: function () { $(this).dialog("destory"); dialog.remove(); }
                , closeText: "×"
            });
            window["dialog"] = dialog;
        }

        function ChangeAdType() {
            // 广告类型，来源于 AdType枚举，0：富文本 ， 1：幻灯片 ， 2： HTML代码
            switch ($("#adType").val()) {
                // 富文本模式                                                 
                case "0":
                    // 销毁编辑器
                    if (window["ckeditor"]) { window["ckeditor"].destroy(true); window["ckeditor"] = null }
                    // 创建编辑器
                    window["ckeditor"] = CKEDITOR.replace("ckeditor", { enterMode: 2, height: 500, removePlugins: "save,new" });
                    $("#richtext_box").show();
                    $("#slide_box").hide();
                    break;
                // 幻灯片模式                                                 
                case "1":
                    $("#slide_box").show();
                    $("#richtext_box").hide();
                    break;
                //源代码模式                                                 
                case "2":
                    // 销毁编辑器
                    if (window["ckeditor"]) { window["ckeditor"].destroy(); window["ckeditor"] = null }
                    $("#richtext_box").show();
                    $("#slide_box").hide();
                    break;
            }
        }
        var thumbUrl = '<%=Url.Action("Thumb","Home",new {Area = "Website"}) %>';
        $(function () {
            ChangeAdType();
            $("#adType").change(ChangeAdType);

            $("#slide_insert").click(function () {

                window["SetUrl"] = function (filePath) {
                    $("#slide_box table tbody").append("<tr><td class=\"textCenter width120\"> <img title=\"点击更换图片\" style=\"cursor: pointer;\" src=\"" + thumbUrl + "?s=" + filePath + "\" alt=\"\" /> <input type=\"hidden\" name=\"filePath\" value=\"" + filePath + "\" /> </td> <td> <span>标题:</span> <input type=\"text\" name=\"title\" class=\"width300\" /> <br /> <span>链接:</span> <input type=\"text\" name=\"redirect\" class=\"width300\" /><br /> <span>排序:</span><input type=\"text\" name=\"sequence\" class=\"width50\" /></td><td class=\"textCenter width80\"><input type=\"button\" value=\"删除\" name=\"slide_delete\" /></td></tr>");
                    $("#slide_box tbody :text[name='sequence']").each(function (i, n) { this.value = i });
                    window["dialog"].dialog("close");
                }
                showDialog();
            });
            $("#slide_box img").live("click", function () {
                _img = this;
                window["SetUrl"] = function (filePath) {
                    _img.src = thumbUrl + "?s=" + filePath;
                    $(_img).parent().find(":hidden[name='filePath']").val(filePath);
                    $("#slide_box tbody :text[name='sequence']").each(function (i, n) { this.value = i });
                    window["dialog"].dialog("close");
                }
                showDialog();
            });
            $(":button[name='slide_delete']").live("click", function () { $(this).parent().parent().remove(); });
        });
    </script>
</asp:Content>
